home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / MPEG / AMPBitstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  2.5 KB  |  121 lines

  1. /* 
  2.  *  AmpBitstream.h
  3.  *
  4.  *  Code from
  5.  *            NekoAmp 1.3 decoder by Avery Lee
  6.  *
  7.  *  FlasKMPEG
  8.  *    Copyright (C) Alberto Vigata - January 2000
  9.  *
  10.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  11.  *    
  12.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  13.  *  it under the terms of the GNU General Public License as published by
  14.  *  the Free Software Foundation; either version 2, or (at your option)
  15.  *  any later version.
  16.  *   
  17.  *  FlasKMPEG is distributed in the hope that it will be useful,
  18.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  *  GNU General Public License for more details.
  21.  *   
  22.  *  You should have received a copy of the GNU General Public License
  23.  *  along with GNU Make; see the file COPYING.  If not, write to
  24.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  25.  *
  26.  */
  27.  
  28. #ifndef f_AMPLIB_BITSTREAM_H
  29. #define f_AMPLIB_BITSTREAM_H
  30.  
  31. #include "IAMPDecoder.h"
  32.  
  33. // max layer2 buffer -> 144000 * 384 / 32000 + 1 - 4 = 1725 bytes
  34. // max layer3 buffer -> 144000 * 320 / 32000 + 512 - 4 = 1948 bytes
  35.  
  36. #define BUFFER_SIZE        (2048)
  37. #define BUFFER_MASK        (BUFFER_SIZE - 1)
  38.  
  39. class AMPBitstream {
  40. protected:
  41.     IAMPBitsource *pSource;
  42.  
  43. private:
  44.     unsigned char buf[BUFFER_SIZE];
  45.     int bitcnt;
  46.     int bufpoint;
  47.     int bufindex, bufindexw;
  48.     unsigned long bitheap;
  49.  
  50.     long _getbits(unsigned char bits);
  51.     long _peekbits(unsigned char bits);
  52.     long _peekbits2(unsigned char bits);
  53.  
  54. public:
  55.  
  56.     void resetbits(int bytes);
  57.     void fillbits(int bytes);
  58.     void rewind(int bytes);
  59.     void rewindbits(int bits);
  60.     int tellbits();
  61.  
  62.     long peekbits(unsigned char bits) {
  63.         if (bitcnt > 24-(int)bits)
  64.             return _peekbits(bits);
  65.  
  66.         return bitheap >> (32-bits);
  67.     }
  68.  
  69.     long peekbits2(unsigned char bits) {
  70.         if (bitcnt > 24-(int)bits)
  71.             return _peekbits2(bits);
  72.  
  73.         return bitheap >> (32-bits);
  74.     }
  75.  
  76.     void skipbits(unsigned char bits) {
  77.         bitcnt += bits;
  78.         bitheap <<= bits;
  79.     }
  80.  
  81.     void skipbit() {
  82.         bitcnt++;
  83.         bitheap += bitheap;
  84.     }
  85.  
  86.     long getbits(unsigned char bits) {
  87.         long rv;
  88.         
  89.         if (!bits)
  90.             return 0;
  91.  
  92.         if (bitcnt > 24-(int)bits)
  93.             return _getbits(bits);
  94.  
  95.         rv = bitheap >> (32-bits);
  96.  
  97.         bitcnt += bits;
  98.  
  99.         bitheap <<= bits;
  100.  
  101.         return rv;
  102.     }
  103.  
  104.     unsigned long getflag() {
  105.         long rv;
  106.         
  107.         if (bitcnt > 23)
  108.             return _getbits(1);
  109.  
  110.         rv = bitheap;
  111.  
  112.         ++bitcnt;
  113.  
  114.         bitheap <<= 1;
  115.  
  116.         return rv&0x80000000;
  117.     }
  118. };
  119.  
  120. #endif
  121.